<template>
  <div class="bg">
    <div class="login">
      <h2>外卖管理平台</h2>
      <el-form ref="formRef" size="small" :rules="rules" class="demo-ruleForm" :model="Fromdata">
        <el-form-item prop="account">
          <i class="el-icon-user"></i>
          <el-input
            prefix-icon="iconfont icon-yonghu"
            v-model="Fromdata.account"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <i class="el-icon-lock"></i>
          <el-input
            prefix-icon="iconfont icon-suoding"
            v-model="Fromdata.password"
            show-password
          >
          </el-input>
        </el-form-item>
      </el-form>
      <el-button size="small" type="warning" @click="submit">登录</el-button>
    </div>
  </div>
</template>

<script>
//解构vuex辅助函数
import { mapActions } from "vuex";
export default {
  data() {
    return {
      Fromdata: {
        account: "",
        password: "",
      },
      rules:{
        account:[
          {required:true,message:'请输入账号'},
          {min:3,max:12,message:'长度在3-12位'}
        ],
        password:[
          {required:true,message:'请输入密码'},
          {min:6,max:12,message:'长度在6-12位'}
        ]
      }
    };
  },
methods:{
  ...mapActions('user',['A_login']),
  //登录操作
  submit(){
    this.$refs.formRef.validate(async valid=>{
      //判断
      if (valid) {
       await this.A_login(this.Fromdata)
       this.$router.push('/home')
        
      } else {
        console.log('验证失败');
      }
    })
  }
}
};
</script>

<style lang="scss" scoped>
.el-icon-user ,.el-icon-lock{
  position: relative;
  top: 35px;
  left: 10px;
  z-index: 99999;
}
.bg {
  width: 100%;
  height: 100%;
  background-image: url("@/assets/imgs/meituan.jpg");
  position: relative;
  .login {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    h2 {
      text-align: center;
      margin-bottom: 20px;
      font-size: 30px;
      color: #e3bc25;
    }
    .el-button {
      width: 100%;
      background-color: #e3bc25;
      height: 40px;
      font-size: 18px;
      border: 0;
    }
    .el-form {
      :deep(.el-input__inner) {
        height: 40px;
      }
      :deep(.icon-zhengyan .icon-biyan) {
        font-size: 20px;
      }
    }
  }
}

</style>
